---
title: Spec - howl.util.Matcher
tags: spec
---
<div class="spec-group spec-group-1">

<h1 id="howl.util.matcher">howl.util.Matcher</h1>

<h4 id="matches-if-the-search-matches-exactly">matches if the search matches exactly</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'One'</span><span class="p">,</span><span class="w"> </span><span class="s1">'Green Fields'</span><span class="p">,</span><span class="w"> </span><span class="s1">'two'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'One'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'ne'</span><span class="p">)</span></code></pre>


<h4 id="candidates-are-automatically-converted-to-strings">candidates are automatically converted to strings</h4>

<pre class="highlight moonscript"><code><span class="n">candidate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">setmetatable</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="ss">__tostring:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'auto'</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">candidate</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">candidate</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'auto'</span><span class="p">)</span></code></pre>


<h4 id="candidates-can-be-multi-valued-tables">candidates can be multi-valued tables</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'One'</span><span class="p">,</span><span class="w"> </span><span class="s1">'Uno'</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">c</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'One'</span><span class="p">)</span></code></pre>


<h4 id="multi-valued-candidates-are-automatically-converted-to-strings">multi-valued candidates are automatically converted to strings</h4>

<pre class="highlight moonscript"><code><span class="n">candidate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">setmetatable</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="ss">__tostring:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="s1">'auto'</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">candidate</span><span class="p">,</span><span class="w"> </span><span class="s1">'desc'</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">candidate</span><span class="p">,</span><span class="w"> </span><span class="s1">'desc'</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'auto'</span><span class="p">)</span></code></pre>


<h4 id="prefers-boundary-matches-over-exact-ones">prefers boundary matches over exact ones</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'kiss her'</span><span class="p">,</span><span class="w"> </span><span class="s1">'some/stuff/here'</span><span class="p">,</span><span class="w"> </span><span class="s1">'openssh'</span><span class="p">,</span><span class="w"> </span><span class="s1">'sss hhh'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="s1">'sss hhh'</span><span class="p">,</span><span class="w">
  </span><span class="s1">'some/stuff/here'</span><span class="w">
  </span><span class="s1">'openssh'</span><span class="p">,</span><span class="w">
</span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'ssh'</span><span class="p">)</span></code></pre>


<h4 id="prefers-early-occurring-matches-over-ones-at-the-end">prefers early occurring matches over ones at the end</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'Discard all apples'</span><span class="p">,</span><span class="w"> </span><span class="s1">'all aardvarks'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="s1">'all aardvarks'</span><span class="p">,</span><span class="w">
  </span><span class="s1">'Discard all apples'</span><span class="w">
</span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'aa'</span><span class="p">)</span></code></pre>


<h4 id="prefers-shorter-matching-candidates-over-longer-ones">prefers shorter matching candidates over longer ones</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'x/tools.sh'</span><span class="p">,</span><span class="w"> </span><span class="s1">'x/torx'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="s1">'x/torx'</span><span class="p">,</span><span class="w">
  </span><span class="s1">'x/tools.sh'</span><span class="w">
</span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'to'</span><span class="p">)</span></code></pre>


<h4 id="prefers-tighter-matches-to-longer-ones">prefers tighter matches to longer ones</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'awesome_apples'</span><span class="p">,</span><span class="w"> </span><span class="s1">'an_aardvark'</span><span class="w">  </span><span class="p">}</span><span class="w">

</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="s1">'an_aardvark'</span><span class="p">,</span><span class="w">
  </span><span class="s1">'awesome_apples'</span><span class="p">,</span><span class="w">
</span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'aa'</span><span class="p">)</span></code></pre>


<h4 id="&quot;special&quot;-characters-are-matched-as-is">&quot;special&quot; characters are matched as is</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'Item 2. 1%w'</span><span class="p">,</span><span class="w"> </span><span class="s1">'Item 22 2a'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'Item 2. 1%w'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'%w'</span><span class="p">)</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'.*'</span><span class="p">)</span></code></pre>


<h4 id="boundary-matches-can-not-skip-separators">boundary matches can not skip separators</h4>

<pre class="highlight moonscript"><code><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'nih/says/knights'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'nih/says/knights'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'sk'</span><span class="p">)</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'nk'</span><span class="p">)</span></code></pre>


<h4 id="boundary-matches-are-as-tight-as-possible">boundary matches are as tight as possible</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">how:</span><span class="w"> </span><span class="s1">'boundary'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">}</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">.</span><span class="n">explain</span><span class="w"> </span><span class="s1">'hth'</span><span class="p">,</span><span class="w"> </span><span class="s1">'hail the howl'</span></code></pre>

<div class="spec-group spec-group-2">

<h2 id="(boundary-matches)">(boundary matches)</h2>

<h4 id="matches-if-the-search-matches-at-boundaries">matches if the search matches at boundaries</h4>

<pre class="highlight moonscript"><code><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'green fields'</span><span class="p">,</span><span class="w"> </span><span class="s1">'green sfinx'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'green fields'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'gf'</span><span class="p">)</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'apaass_so'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">({</span><span class="s1">'apaass_so'</span><span class="p">})(</span><span class="s1">'as'</span><span class="p">)</span></code></pre>


<h4 id="matches-if-the-search-matches-at-upper-case-boundaries">matches if the search matches at upper case boundaries</h4>

<pre class="highlight moonscript"><code><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'camelCase'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a CreditCard'</span><span class="p">,</span><span class="w"> </span><span class="s1">'chacha'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'camelCase'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a CreditCard'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'cc'</span><span class="p">)</span></code></pre>


<h4 id="allows-for-multiple-character-boundaries">allows for multiple-character boundaries</h4>

<pre class="highlight moonscript"><code><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'green/_fields'</span><span class="p">,</span><span class="w"> </span><span class="s1">'green sfinx'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'green/_fields'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'gf'</span><span class="p">)</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="explain(search,-text)">explain(search, text)</h2>

<h4 id="sets-.how-to-the-type-of-match">sets .how to the type of match</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'exact'</span><span class="p">,</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">.</span><span class="n">explain</span><span class="p">(</span><span class="s1">'fu'</span><span class="p">,</span><span class="w"> </span><span class="s1">'snafu'</span><span class="p">).</span><span class="n">how</span></code></pre>


<h4 id="returns-a-list-of-{start_position,-length}-segments-indicating-where-&lt;search&gt;-matched">returns a list of {start_position, length} segments indicating where &lt;search&gt; matched</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">how:</span><span class="w"> </span><span class="s1">'exact'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">}</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">.</span><span class="n">explain</span><span class="w"> </span><span class="s1">'ƒlu'</span><span class="p">,</span><span class="w"> </span><span class="s1">'sñaƒlux'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">how:</span><span class="w"> </span><span class="s1">'boundary'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="mi">9</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">}</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">.</span><span class="n">explain</span><span class="w"> </span><span class="s1">'itʂo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'iʂ that ʂo'</span></code></pre>


<h4 id="explains-case-boundary-matches-correctly">explains case boundary matches correctly</h4>

<pre class="highlight moonscript"><code><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">.</span><span class="n">explain</span><span class="w"> </span><span class="s1">'cc'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a CreditCard'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">how:</span><span class="w"> </span><span class="s1">'boundary'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="mi">9</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">}},</span><span class="w"> </span><span class="n">m</span></code></pre>


<h4 id="lower-cases-the-search-and-text-just-as-for-matching">lower-cases the search and text just as for matching</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">not_nil</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">.</span><span class="n">explain</span><span class="w"> </span><span class="s1">'FU'</span><span class="p">,</span><span class="w"> </span><span class="s1">'ʂnafu'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">not_nil</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">.</span><span class="n">explain</span><span class="w"> </span><span class="s1">'fu'</span><span class="p">,</span><span class="w"> </span><span class="s1">'SNAFU'</span></code></pre>


<h4 id="accepts-ustring-both-for-&lt;search&gt;-and-&lt;text&gt;">accepts ustring both for &lt;search&gt; and &lt;text&gt;</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">not_nil</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">.</span><span class="n">explain</span><span class="w"> </span><span class="s1">'FU'</span><span class="p">,</span><span class="w"> </span><span class="s1">'snafu'</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="with-reverse-matching-(reverse-=-true-specified-as-an-option)">with reverse matching (reverse = true specified as an option)</h2>

<h4 id="prefers-late-occurring-exact-matches-over-ones-at-the-start">prefers late occurring exact matches over ones at the start</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'xmatch me'</span><span class="p">,</span><span class="w"> </span><span class="s1">'me xmatch'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="ss">reverse:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="s1">'me xmatch'</span><span class="w">
  </span><span class="s1">'xmatch me'</span><span class="p">,</span><span class="w">
</span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'mat'</span><span class="p">)</span></code></pre>


<h4 id="prefers-late-occurring-boundary-matches-over-ones-at-the-start">prefers late occurring boundary matches over ones at the start</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'match natchos'</span><span class="p">,</span><span class="w"> </span><span class="s1">'me match now'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="ss">reverse:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="s1">'me match now'</span><span class="w">
  </span><span class="s1">'match natchos'</span><span class="p">,</span><span class="w">
</span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'mn'</span><span class="p">)</span></code></pre>


<h4 id="still-prefers-tighter-matches-to-longer-ones">still prefers tighter matches to longer ones</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'an_aardvark'</span><span class="p">,</span><span class="w"> </span><span class="s1">'a_apple'</span><span class="w"> </span><span class="p">}</span><span class="w">

</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="ss">reverse:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="s1">'a_apple'</span><span class="p">,</span><span class="w">
  </span><span class="s1">'an_aardvark'</span><span class="p">,</span><span class="w">
</span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'aa'</span><span class="p">)</span></code></pre>


<h4 id="still-prefers-boundary-matches-over-straight-ones">still prefers boundary matches over straight ones</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'some/stuff/here'</span><span class="p">,</span><span class="w"> </span><span class="s1">'sshopen'</span><span class="p">,</span><span class="w"> </span><span class="s1">'open/ssh'</span><span class="p">,</span><span class="w"> </span><span class="s1">'ss xh'</span><span class="w"> </span><span class="p">}</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="ss">reverse:</span><span class="w"> </span><span class="kc">true</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="s1">'open/ssh'</span><span class="p">,</span><span class="w">
  </span><span class="s1">'sshopen'</span><span class="p">,</span><span class="w">
  </span><span class="s1">'some/stuff/here'</span><span class="w">
</span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'ssh'</span><span class="p">)</span></code></pre>


<h4 id="explain(search,-text)-works-correctly">explain(search, text) works correctly</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">how:</span><span class="w"> </span><span class="s1">'exact'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="mi">7</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">}</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">.</span><span class="n">explain</span><span class="w"> </span><span class="s1">'aƒl'</span><span class="p">,</span><span class="w"> </span><span class="s1">'ƒluxsñaƒlux'</span><span class="p">,</span><span class="w"> </span><span class="ss">reverse:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">how:</span><span class="w"> </span><span class="s1">'boundary'</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">},</span><span class="w"> </span><span class="p">{</span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">}</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="nc">Matcher</span><span class="p">.</span><span class="n">explain</span><span class="w"> </span><span class="s1">'as'</span><span class="p">,</span><span class="w"> </span><span class="s1">'app_spec.fu'</span><span class="p">,</span><span class="w"> </span><span class="ss">reverse:</span><span class="w"> </span><span class="kc">true</span></code></pre>

<div class="spec-group spec-group-3">

<h3 id="handles-boundary-matches">handles boundary matches</h3>

<h4 id="handles-boundary-matches">handles boundary matches</h4>

<pre class="highlight moonscript"><code><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'spec/aplication_spec.moon'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="ss">reverse:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'spec/aplication_spec.moon'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'as'</span><span class="p">)</span></code></pre>


<h4 id="allows-for-multiple-character-boundaries">allows for multiple-character boundaries</h4>

<pre class="highlight moonscript"><code><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'spec/aplication/_spec.moon'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="ss">reverse:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'spec/aplication/_spec.moon'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'as'</span><span class="p">)</span></code></pre>

</div>
</div>
<div class="spec-group spec-group-2">

<h2 id="with-preserve_order-=-true-specified-as-an-option">with preserve_order = true specified as an option</h2>

<h4 id="preserves-order-of-matches,-irrespective-of-match-score">preserves order of matches, irrespective of match score</h4>

<pre class="highlight moonscript"><code><span class="n">c</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="s1">'xabx0'</span><span class="p">,</span><span class="w"> </span><span class="s1">'ax_bx1'</span><span class="p">,</span><span class="w"> </span><span class="s1">'xabx2'</span><span class="p">,</span><span class="w"> </span><span class="s1">'ax_bx3'</span><span class="p">}</span><span class="w">
</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="ss">preserve_order:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">c</span><span class="p">,</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'ab'</span><span class="p">)</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="for-large-data-sets">for large data sets</h2>

<h4 id="returns-a-partial-match-when-more-than-1000-items-match">returns a partial match when more than 1000 items match</h4>

<pre class="highlight moonscript"><code><span class="n">items</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w">  </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2000</span><span class="w">
  </span><span class="s2">"item-</span><span class="si">#{</span><span class="n">i</span><span class="si">}</span><span class="s2">"</span><span class="w">

</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">items</span><span class="w">
</span><span class="n">matches</span><span class="p">,</span><span class="w"> </span><span class="n">partial</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'item'</span><span class="p">)</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1000</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">matches</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">partial</span><span class="w">

</span><span class="n">matches</span><span class="p">,</span><span class="w"> </span><span class="n">partial</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'item-123'</span><span class="p">)</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="o">#</span><span class="n">matches</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mi">1000</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">partial</span></code></pre>


<h4 id="allows-slightly-more-than-1000-when-the-alternative-would-be-irritating">allows slightly more than 1000 when the alternative would be irritating</h4>

<pre class="highlight moonscript"><code><span class="n">items</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w">  </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">1100</span><span class="w">
  </span><span class="s2">"item-</span><span class="si">#{</span><span class="n">i</span><span class="si">}</span><span class="s2">"</span><span class="w">

</span><span class="n">m</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Matcher</span><span class="w"> </span><span class="n">items</span><span class="w">
</span><span class="n">matches</span><span class="p">,</span><span class="w"> </span><span class="n">partial</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">m</span><span class="p">(</span><span class="s1">'item'</span><span class="p">)</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equals</span><span class="w"> </span><span class="mi">1100</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">matches</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">is_false</span><span class="w"> </span><span class="n">partial</span></code></pre>

</div>
</div>
